namespace Microsoft.VisualStudio.EnterpriseTools.OperationDesigner
{
    using System;
    using System.Runtime.InteropServices;

    [StructLayout(LayoutKind.Sequential)]
    public struct ProcessKeyResult
    {
        private const int EXPAND_BRANCH = 2;
        private const int LOCAL = 4;
        private const int EDIT_MODE = 8;
        private NavigationDirection treeNav;
        private KeyAction action;
        private Type columnType;
        private Type branchType;
        private int flags;
        public ProcessKeyResult(KeyAction action)
        {
            this.columnType = null;
            this.branchType = null;
            this.flags = 4;
            this.treeNav = NavigationDirection.Right;
            this.action = action;
        }

        public KeyAction Action
        {
            get
            {
                return this.action;
            }
            set
            {
                this.action = value;
            }
        }
        public Type ColumnType
        {
            get
            {
                return this.columnType;
            }
            set
            {
                this.columnType = value;
            }
        }
        public Type BranchType
        {
            get
            {
                return this.branchType;
            }
            set
            {
                this.branchType = value;
            }
        }
        public NavigationDirection Direction
        {
            get
            {
                return this.treeNav;
            }
            set
            {
                this.treeNav = value;
            }
        }
        public bool ExpandBranch
        {
            get
            {
                return this.GetFlag(2);
            }
            set
            {
                this.SetFlag(2, value);
            }
        }
        public bool Local
        {
            get
            {
                return this.GetFlag(4);
            }
            set
            {
                this.SetFlag(4, value);
            }
        }
        public bool StartLabelEdit
        {
            get
            {
                return this.GetFlag(8);
            }
            set
            {
                this.SetFlag(8, value);
            }
        }
        private bool GetFlag(int flagValue)
        {
            return ((this.flags & flagValue) != 0);
        }

        private void SetFlag(int flagValue, bool value)
        {
            if (value)
            {
                this.flags |= flagValue;
            }
            else
            {
                this.flags &= ~flagValue;
            }
        }
    }
}

